package top.yokey.android.base;

import android.app.Application;
import android.content.SharedPreferences;
import android.os.Build;

import java.util.HashMap;

import top.yokey.android.http.HttpHelp;

//程序运行的时候，一定会走到这里，而且是第一个类走这
public class App extends Application {

    private static App instance = null;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    public static App get() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        //第三方框架，自定义的框架初始化一般放在 Applicaiton 类下的 oncreate 方法
        //初始化网络请求框架
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("model", Build.MODEL);
        HttpHelp.get().init(this, "http://192.168.56.1/api/", hashMap);
        //初始化Share轻量级存储
        sharedPreferences = getSharedPreferences("android", MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }

    //alt + insert 选择 getter and setter
    public SharedPreferences getSharedPreferences() {
        return sharedPreferences;
    }

    public void setSharedPreferences(SharedPreferences sharedPreferences) {
        this.sharedPreferences = sharedPreferences;
    }

    public SharedPreferences.Editor getEditor() {
        return editor;
    }

    public void setEditor(SharedPreferences.Editor editor) {
        this.editor = editor;
    }

}
